<!DOCTYPE HTML>
<html>
 <head>
 <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript">
var deviceReady = false;
var persistent_root;
var data_dir;
var dir="Listenner";
var getFileSystemRoot = (function () {
		var onError = function (error) {
            alert('unable to retrieve file system: ' + error.code);
        };
        // one-time retrieval of the root file system entry
        if (typeof persistent_root === 'undefined') {
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
                function (fileSystem) {
                    persistent_root = fileSystem.root;
					d=fileSystem.root.getDirectory(dir,{create:true,exclusive:false},gotDir,onError);
                }, onError);
        }

        // public function returns private root entry
        return persistent_root;
 
    });
	

function onError(e){
	alert("Get Directory Error:"+e.code);
}
function gotDir(d)
{
	console.log("1:"+d.name);
	data_dir=d;
}
	
function downFile()//url,filePath)
{
console.log("persistent_root type:"+typeof persistent_root);
	var fileTransfer = new FileTransfer();
	var url="http://download.putclub.com/newupdate/listening/bdc2000/qs02.mp3";
	console.log("data_dir type:"+typeof data_dir);
	var filePath=data_dir.fullPath +"/gs02.mp3";
	fileTransfer.download(
		url,
		filePath,
		function(entry) {
			alert("download complete: " + entry.fullPath);
		},
		function(error) {
			alert("download error code" + error.code);
		}
	);
}
	
function init() {
        document.addEventListener("deviceready", function () {
            deviceReady = true;
            alert("Device=" + device.platform + " " + device.version);
            getFileSystemRoot();
        }, true);
        window.setTimeout(function () {
            if (!deviceReady) {
                alert("Error: Cordova did not initialize.  Demo will not run correctly.");
            }
        }, 1000);
    }
</script>

</head>
<body onLoad="init();" style="width:480px; height:800px">
 <a href="#" class="btn large" onclick="downFile();">download file</a>
</body>
</html>